package com.vitaf.cash.app.ui.adapter

import androidx.recyclerview.widget.RecyclerView
import com.vitaf.cash.app.R
import com.vitaf.cash.lib.adapter.VitafRecyclerViewAdapter
import com.vitaf.cash.lib.adapter.VitafViewHolderHelper
import com.vitaf.cash.lib.shapeview.layout.VitafRelativeLayout
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/19 13:54
 * @Annotation：认证流程 - 性别选择
 */
class VitafStepGenderItemApt(recyclerView: RecyclerView?) :
    VitafRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.vitaf_fmt_step_general_gender_child_item) {
    override fun setItemChildListener(helper: VitafViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.genderItemLayout)//选择
    }

    override fun fillData(helper: VitafViewHolderHelper, position: Int, model: JSONObject) {
        val genderItemLayout = helper.getView<VitafRelativeLayout>(R.id.genderItemLayout)
        val imgGenderType = helper.getImageView(R.id.imgGenderType)
        val textGenderTitle = helper.getTextView(R.id.textGenderTitle)
        val imgGenderSelector = helper.getImageView(R.id.imgGenderSelector)
        textGenderTitle.text = model.optString("title")

        val value = model.optString("value").uppercase()
        if (model.optBoolean("isSelected", false)) {
            genderItemLayout.getShapeDrawableBuilder()
                .setSolidColor(getColor(R.color.gombe_credit_fffff5b5))
                .setStrokeColor(getColor(R.color.theme))
                .setStrokeSize(mContext.resources.getDimension(com.vitaf.cash.lib.R.dimen.dp_1).toInt())
                .intoBackground()
            imgGenderSelector.setImageResource(R.mipmap.gombe_credit_image_gender_selected_icon)
            textGenderTitle.setTextColor(getColor(R.color.gombe_credit_ff1d1e20))

            if (value == "FEMALE" || value == "FEMELLE"){
                imgGenderType.setImageResource(R.mipmap.gombe_credit_image_gender_female_selected_icon)
            } else {
                imgGenderType.setImageResource(R.mipmap.gombe_credit_image_gender_male_selected_icon)
            }
        } else {
            genderItemLayout.getShapeDrawableBuilder()
                .setSolidColor(getColor(R.color.gombe_credit_FFF9F9F7))
                .setStrokeColor(getColor(R.color.gombe_credit_FFF9F9F7))
                .setStrokeSize(mContext.resources.getDimension(com.vitaf.cash.lib.R.dimen.dp_1).toInt())
                .intoBackground()
            imgGenderSelector.setImageResource(R.mipmap.gombe_credit_image_gender_normal_icon)
            textGenderTitle.setTextColor(getColor(R.color.gombe_credit_ffc8c8c8))

            if (value == "FEMALE" || value == "FEMELLE"){
                imgGenderType.setImageResource(R.mipmap.gombe_credit_image_gender_female_normal_icon)
            } else {
                imgGenderType.setImageResource(R.mipmap.gombe_credit_image_gender_male_normal_icon)
            }
        }
    }
}